﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Qiang.Geometry
{
    public class WktReader
    {

        public void Example()
        {
            string wkt = "LINESTRING ZM( 10 20 30 20, 10 50 20 30, 20 10 20 20 )";

            Qiang.Geometry.WktReader.ReadLineString(wkt);
        }


        public static void ReadLineString(string wktStr)
        {
            List<Coordinate> coors = new List<Coordinate>();

            string str = wktStr.Substring(14);
            str = str.Substring(0, str.Length - 1);
            char[] separator = new char[1];
            separator[0] = ',';

            string[] strs = str.Split(separator);
            
            separator[0] = ' ';
          
            for (int i = 0; i < strs.Length; i++)
            {
                Coordinate coor = new Coordinate();

                string[] coorStrs = strs[i].Split(separator);

                int num=0;
               
                for (int j = 0; j < coorStrs.Length; j++)
                {
                    if (coorStrs[j] != "")
                    {
                        coor[num] = double.Parse(coorStrs[j]);
                        num++;
                    }
                }

                coors.Add(coor);
            }

        }


    }
}
